<template>
  <div class="stuCourseContainer">
    <BasicTable @handler="tableHandler" :data="data" :column="column"></BasicTable>
  </div>
</template>

<script>
import BasicTable from "@/components/BasicTable/BasicTable"
import { tableColumn } from '@/constants/stuCourse'
import { getStuCourse, deleteCourse } from '@/api/user'

export default {
  name: "index",
  components: {
    BasicTable
  },
  data() {
    return {
      column: tableColumn,
      data: []
    }
  },
  methods: {
    tableHandler(val) {
      let { type, data } = val
      console.log(type, data)
      switch(type) {
        case 'delete':
          this.deleteCourse(data)
          break
        default:
          break
      }
    },
    async getData() {
      const res = await getStuCourse()
      if (res.success == true) {
        this.data = res.data
      } else {
        this.$message.error(res.errorMsg)
      }
    },
    async deleteCourse(val) {
      const res = await deleteCourse(val.courseId)
      if (res.success == true) {
        this.$message.success('退课成功！')
      } else {
        this.$message.error(res.errorMsg)
      }
    }
  },
  created() {
    this.getData()
  }
}
</script>

<style scoped lang="sass">
.stuCourseContainer
  padding: 20px
</style>
